import request from '@/config/axios'

export interface OcrConfigVO {
  id?: number
  name: string
  type: string
  appId: string
  apiKey: string
  secretKey: string
  status: number
  createTime?: Date
  updateTime?: Date
}

export interface OcrConfigPageReqVO extends PageParam {
  name?: string
  type?: string
  status?: number
  createTime?: Date[]
}

export interface OcrRecognizeReqVO {
  configId: number
  imageUrl: string
}

export interface OcrRecognizeRespVO {
  text: string
  confidence: number
  words: Array<{
    text: string
    confidence: number
    location: {
      left: number
      top: number
      width: number
      height: number
    }
  }>
}

export interface OcrRecordVO {
  id?: number
  configId: number
  configName?: string
  ocrType: string
  fileName: string
  fileUrl: string
  imageUrl?: string
  recognitionText: string
  recognitionResult: string
  confidence: number
  processingTime: number
  status: number
  errorMessage?: string
  userId?: number
  createTime?: Date
}

export interface OcrRecordPageReqVO extends PageParam {
  configId?: number
  type?: string
  fileName?: string
  status?: number
  createTime?: Date[]
}

// OCR配置管理API
export const getOcrConfigPage = (params: OcrConfigPageReqVO) => {
  return request.get({ url: '/infra/ocr-config/page', params })
}

export const getOcrConfig = (id: number) => {
  return request.get({ url: '/infra/ocr-config/get?id=' + id })
}

export const createOcrConfig = (data: OcrConfigVO) => {
  return request.post({ url: '/infra/ocr-config/create', data })
}

export const updateOcrConfig = (data: OcrConfigVO) => {
  return request.put({ url: '/infra/ocr-config/update', data })
}

export const deleteOcrConfig = (id: number) => {
  return request.delete({ url: '/infra/ocr-config/delete?id=' + id })
}

export const getOcrConfigSimpleList = () => {
  return request.get({ url: '/infra/ocr-config/simple-list' })
}

// OCR识别API
export const recognizeOcr = (data: OcrRecognizeReqVO) => {
  return request.post({ url: '/infra/ocr/recognize', data })
}

// OCR记录查询API
export const getOcrRecordPage = (params: OcrRecordPageReqVO) => {
  return request.get({ url: '/infra/ocr-record/page', params })
}

export const getOcrRecord = (id: number) => {
  return request.get({ url: '/infra/ocr-record/get?id=' + id })
}

export const deleteOcrRecord = (id: number) => {
  return request.delete({ url: '/infra/ocr-record/delete?id=' + id })
}
